import { getAction, putAction, postAction, deleteAction, downloadAction } from '@/api/baseAPI'

/** 登录接口 */
// 获取图形验证码
export const apiGetRandomImage = timestamp => downloadAction('/sys/randomImage/' + timestamp)
// 登录
export const login = params => postAction('/sys/login', params)
// 登出
export const logout = () => postAction('/sys/logout')
// 查询用户权限
export const queryPermissionsByUser = params => getAction('/sys/permission/getUserPermissionByToken', params)

/** 通用接口 */
// 重复校验
export const apiDuplicateCheck = params => getAction('/sys/duplicate/check', params)
// 文件下载
export const apiDownloadFile = (fileName, needDelete) => downloadAction('/common/download', { fileName, delete: needDelete || false })

/** 用户管理 */
// 查询用户列表
export const apiListUser = params => getAction('/sys/user/list', params)
// 添加用户
export const apiAddUser = params => postAction('/sys/user/add', params)
// 编辑用户
export const apiEditUser = params => putAction('/sys/user/edit', params)
// 查询用户角色
export const apiQueryUserRole = params => getAction('/sys/user/queryUserRole', params)
// 查询用户部门
export const apiQueryUserDepartList = params => getAction('/sys/user/userDepartList', params)
// 导出用户列表
export const apiExportUser = params => getAction('/sys/user/export', params)

/** 角色管理 */
// 查询所有角色
export const apiQueryAllRole = params => getAction('/sys/role/queryall', params)
// 查询角色列表
export const apiQueryRoleList = params => getAction('/sys/role/list', params)
// 添加角色
export const apiAddRole = params => postAction('/sys/role/add', params)
// 编辑角色
export const apiEditRole = params => putAction('/sys/role/edit', params)
// 查询角色树
export const apiQueryTreeListForRole = params => getAction('/sys/role/queryTreeList', params)
// 查询角色拥有的权限
export const apiQueryRolePermission = params => getAction('/sys/permission/queryRolePermission', params)
// 保存角色拥有的权限
export const apiSaveRolePermission = params => postAction('/sys/permission/saveRolePermission', params)
// 查询数据规则
export const apiQueryDataRule = (permissionId, roleId, params) => getAction('/sys/role/datarule/' + permissionId + '/' + roleId, params)
// 保存数据规则
export const apiSaveDataRule = params => postAction('/sys/role/datarule', params)

/** 权限管理 */
// 查询权限列表
export const apiQueryPermissionList = params => getAction('/sys/permission/list', params)
// 查询权限树
export const apiQueryTreeList = params => getAction('/sys/permission/queryTreeList', params)
// 添加权限
export const apiAddPermission = params => postAction('/sys/permission/add', params)
// 编辑权限
export const apiEditPermission = params => putAction('/sys/permission/edit', params)
// 删除权限
export const apiDelPermission = params => deleteAction('/sys/permission/delete', params)
// 按权限ID查询权限规则
export const apiQueryPermRuleListByPermId = params => getAction('/sys/permission/getPermRuleListByPermId', params)
// 添加权限规则
export const apiAddPermissionRule = params => postAction('/sys/permission/addPermissionRule', params)
export const apiEditPermissionRule = params => putAction('/sys/permission/editPermissionRule', params)
export const apiDelPermissionRule = params => deleteAction('/sys/permission/deletePermissionRule', params)

/** 部门管理 */
export const apiQueryDepartIdTree = params => getAction('/sys/sysDepart/queryIdTree', params)
export const apiQueryDepartTreeList = params => getAction('/sys/sysDepart/queryTreeList', params)
export const apiQueryDepartByKeywords = params => getAction('/sys/sysDepart/searchBy', params)
export const apiAddDepart = params => postAction('/sys/sysDepart/add', params)
export const apiEditDepart = params => putAction('/sys/sysDepart/edit', params)
export const apiDelDepart = params => deleteAction('/sys/sysDepart/delete', params)
export const apiQueryDepartPermission = params => getAction('/sys/permission/queryDepartPermission', params)
export const apiSaveDepartPermission = params => postAction('/sys/permission/saveDepartPermission', params)
export const apiQueryDepartDataRule = (permissionId, departId, params) => getAction('/sys/sysDepartPermission/datarule/' + permissionId + '/' + departId, params)
export const apiSaveDepartDataRule = params => postAction('/sys/sysDepartPermission/datarule', params)

/** 字典管理 */
// 查询字典列表
export const apiQueryDictList = params => getAction('/sys/dict/list', params)
export const apiAddDict = params => postAction('/sys/dict/add', params)
export const apiEditDict = params => putAction('/sys/dict/edit', params)
export const apiDelDict = params => deleteAction('/sys/dict/delete', params)
// 字典标签专用（通过code获取字典数组）
export const apiGetDictItems = (code, params) => getAction(`/sys/dict/getDictItems/${code}`, params)
// 查询字典项列表
export const apiQueryDictItemList = params => getAction('/sys/dictItem/list', params)
export const apiAddDictItem = params => postAction('/sys/dictItem/add', params)
export const apiEditDictItem = params => putAction('/sys/dictItem/edit', params)
export const apiDelDictItem = params => deleteAction('/sys/dictItem/delete', params)
